package com.yanqu.road.entity.activity.jiuzhou;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.DataStatus;
import com.yanqu.road.entity.FieldTypeAnnotation;
import com.yanqu.road.entity.activity.jiuzhou.game.CrossJiuZhouGameData;
import org.apache.mina.util.ConcurrentHashSet;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 玩家布阵信息
 */
@FieldTypeAnnotation(tableName = "t_c_jiu_zhou_room_data")
public class CrossJiuZhouRoomData extends DataObject {

    @FieldTypeAnnotation(desc = "活动ID", select = true, update = true)
    private int activityId;

    @FieldTypeAnnotation(desc = "房间id", update = true)
    private int roomId;

    @FieldTypeAnnotation(desc = "赛区类型")
    private int zone;

    @FieldTypeAnnotation(desc = "轮次id")
    private int round;

    @FieldTypeAnnotation(desc = "房间状态 1:备战期 2:战斗期 3:已结束")
    private int state;

    @FieldTypeAnnotation(desc = "用户列表")
    private List<Long> roomUserIdList = new ArrayList<>();

    @FieldTypeAnnotation(desc = "战场数据")
    private CrossJiuZhouGameData gameData = null;

    @FieldTypeAnnotation(desc = "观战列表")
    private Set<Long> watchUserIdList = new ConcurrentHashSet<>();

    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        if (this.activityId != activityId) {
            this.activityId = activityId;
            setOp(DataStatus.Update);
        }
    }

    public int getRound() {
        return round;
    }

    public void setRound(int round) {
        if (this.round != round) {
            this.round = round;
            setOp(DataStatus.Update);
        }
    }

    public int getRoomId() {
        return roomId;
    }

    public void setRoomId(int roomId) {
        if (this.roomId != roomId) {
            this.roomId = roomId;
            setOp(DataStatus.Update);
        }
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        if (this.state != state) {
            this.state = state;
            setOp(DataStatus.Update);
        }
    }

    public List<Long> getRoomUserIdList() {
        return roomUserIdList;
    }

    public void setRoomUserIdList(List<Long> roomUserIdList) {
        if (roomUserIdList == null) {
            return;
        }
        this.roomUserIdList = roomUserIdList;
        setOp(DataStatus.Update);
    }

    public CrossJiuZhouGameData getGameData() {
        return gameData;
    }

    public void setGameData(CrossJiuZhouGameData gameData) {
        if (gameData == null) {
            return;
        }
        this.gameData = gameData;
        setOp(DataStatus.Update);
    }

    public int getZone() {
        return zone;
    }

    public void setZone(int zone) {
        if (this.zone != zone) {
            this.zone = zone;
            setOp(DataStatus.Update);
        }
    }


    public void addRoomUser(long userId) {
        //如果有了不能重复添加
        if (this.roomUserIdList.contains(userId)) {
            return;
        }
        // 添加一个用户
        this.roomUserIdList.add(userId);
        setOp(DataStatus.Update);
    }

    public int getUserNum() {
        return this.roomUserIdList.size();
    }

    public Set<Long> getWatchUserIdList() {
        return watchUserIdList;
    }

    public void setWatchUserIdList(Set<Long> watchUserIdList) {
        if (watchUserIdList == null) {
            return;
        }
        this.watchUserIdList = watchUserIdList;
        setOp(DataStatus.Update);
    }

    public void addWatchUserId(long userId) {
        this.watchUserIdList.add(userId);
        setOp(DataStatus.Update);
    }

    public void removeWatchUserId(long userId) {
        this.watchUserIdList.remove(userId);
        setOp(DataStatus.Update);
    }
}
